package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 组织表
 */

@Entity
@Table(name = "organization")
public
class Organization extends SuperClassEntity<Organization> {

    /**
     * 组织名称
     */
    private String organizationName;
    /**
     * 组织描述
     */
    private String organizationDesc;
    /**
     * 组织左
     */
    private Integer lft;
    /**
     * 组织右
     */
    private Integer rgt;
    /**
     * 等级
     */
    private Integer lvl;
    /**
     * 上级组织
     */
    private Long parentId;
    /**
     * 首字母
     */
    private String firstLetter;

    /**
     * 所有上级id，使用逗号分隔
     */
    @Column(length = 500)
    private String parentIds;
    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;


    public Organization() {
    }

    public Organization(String organizationName, String firstLetter, String organizationDesc, Integer lft, Integer rgt, Integer lvl, Long parentId) {
        this.organizationName = organizationName;
        this.firstLetter = firstLetter;
        this.organizationDesc = organizationDesc;
        this.lft = lft;
        this.rgt = rgt;
        this.lvl = lvl;
        this.parentId = parentId;
    }

    public String getOrganizationName() {
        return organizationName;
    }

    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;
    }

    public String getOrganizationDesc() {
        return organizationDesc;
    }

    public void setOrganizationDesc(String organizationDesc) {
        this.organizationDesc = organizationDesc;
    }

    public Integer getLft() {
        return lft;
    }

    public void setLft(Integer lft) {
        this.lft = lft;
    }

    public Integer getRgt() {
        return rgt;
    }

    public void setRgt(Integer rgt) {
        this.rgt = rgt;
    }

    public Integer getLvl() {
        return lvl;
    }

    public void setLvl(Integer lvl) {
        this.lvl = lvl;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getFirstLetter() {
        return firstLetter;
    }

    public void setFirstLetter(String firstLetter) {
        this.firstLetter = firstLetter;
    }

    public String getParentIds() {
        return parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    @Override
    public JSONObject toJSONObject(){
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("organizationName", StringConverters.null2String(getOrganizationName()));
        jsonObject.put("organizationDesc", StringConverters.null2String(getOrganizationDesc()));
        jsonObject.put("lft",StringConverters.null2String(getLft()));
        jsonObject.put("lvl",StringConverters.null2Int(getLvl()));
        jsonObject.put("firstLetter",StringConverters.null2String(getFirstLetter()));
        jsonObject.put("enterpriseName",getEnterprise()==null?"":getEnterprise().getEnterpriseName());



        return jsonObject;
    }
}
